package com.seagull.sb.bo.impl;

import java.util.Collections;
import java.util.List;

import com.seagull.sb.bo.NoticeBO;
import com.seagull.sb.dao.NoticeDAO;
import com.seagull.sb.domain.Notice;
import com.seagull.sb.domain.NoticeSubject;
import com.seagull.sb.dto.NoticeDto;
import com.seagull.sb.util.SBRequestContext;

public class NoticeBOImpl extends BaseBOImpl implements NoticeBO{
	private NoticeDAO noticeDAO;
	
	public List<Notice> getNotice(SBRequestContext rc, NoticeDto noticeDto){
		try{
			
			 return noticeDAO.getNotice(rc);
		}catch(Exception e){
			e.printStackTrace();
		}
		return Collections.EMPTY_LIST;
	}

	public List<NoticeSubject> getNoticeSubjects(SBRequestContext rc){
		try{
			
			 return noticeDAO.getNoticeSubjects(rc);
		}catch(Exception e){
			e.printStackTrace();
		}
		return Collections.EMPTY_LIST;
	}
	
	public List<Notice> viewedNotice(SBRequestContext rc, NoticeDto noticeDto){
		try{
			 List<Notice> notices = noticeDAO.getNotice(rc, noticeDto);
			 if(notices.size() > 0){
				 System.out.println("Updated the notice : "+ noticeDto.getId() +" with viewed status.");
				 // update read status.
				 
			 }
			 return notices;
		}catch(Exception e){
			e.printStackTrace();
		}
		return Collections.EMPTY_LIST;
	}

	public List<Notice> saveNotice(SBRequestContext rc,Notice notice){
		
		try {
			boolean noticeSaved = noticeDAO.saveNotice(rc,notice);
			if(noticeSaved && notice.getId() > 0){
				noticeDAO.saveNoticeAudit(rc, notice); 
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return Collections.EMPTY_LIST;
	}
	
	public NoticeDAO getNoticeDAO() {
		return noticeDAO;
	}
	public void setNoticeDAO(NoticeDAO noticeDAO) {
		this.noticeDAO = noticeDAO;
	}
}
